{% extends "base.html" %}

{% block content %}
<div class="row">
    <div class="col-md-12 mb-4">
        <div class="d-flex justify-content-between align-items-center">
            <h2>{{ article.title }}</h2>
            <div>
                <a href="{{ url_for('articles.index') }}" class="btn btn-outline-primary">返回文章列表</a>
                {% if current_user.id == article.author.id or current_user.is_admin() %}
                <a href="{{ url_for('articles.edit', id=article.id) }}" class="btn btn-primary">编辑文章</a>
                {% endif %}
            </div>
        </div>
        <div class="text-muted mt-2">
            <span>作者: <a href="{{ url_for('users.profile', id=article.author.id) }}">{{ article.author.name }}</a></span>
            <span class="mx-2">|</span>
            <span>发布时间: {{ article.created_at.strftime('%Y-%m-%d %H:%M') }}</span>
            {% if article.updated_at != article.created_at %}
            <span class="mx-2">|</span>
            <span>更新时间: {{ article.updated_at.strftime('%Y-%m-%d %H:%M') }}</span>
            {% endif %}
        </div>
        <div class="mt-2">
            {% for skill in article.skills %}
            <a href="{{ url_for('articles.by_skill', skill_id=skill.id) }}" class="badge bg-secondary text-decoration-none">{{ skill.name }}</a>
            {% endfor %}
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-body">
                <div class="article-content">
                    {{ article.content|safe }}
                </div>
            </div>
        </div>
    </div>
</div>

{% if current_user.id == article.author.id or current_user.is_admin() %}
<div class="row mt-4">
    <div class="col-md-12">
        <div class="d-flex justify-content-end">
            <a href="{{ url_for('articles.edit', id=article.id) }}" class="btn btn-primary me-2">编辑文章</a>
            <a href="{{ url_for('articles.delete', id=article.id) }}" class="btn btn-danger" onclick="return confirm('确定要删除此文章吗？');">删除文章</a>
        </div>
    </div>
</div>
{% endif %}
{% endblock %}